package com.junhong.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.junhong.entity.User;
import com.junhong.service.UserService;
import com.opensymphony.xwork2.ActionSupport;

public class UserLoginAction extends ActionSupport {
	private static final long serialVersionUID = 1L;

	private String userName;
	private String password;
	private String codeName;//获取动态生成验证码的值
	private String codeNamev;//获取输入验证码的值
	@Resource
	private UserService userService;
	
	public String login() {
		HttpServletRequest request = ServletActionContext.getRequest();
		User user = new User();
		user.setUserName(userName);
		user.setPassword(password);
		System.out.print("****************************************************************************"+codeName);
		if(userService.loginUser(user)) {
			if(codeName.equals(codeNamev)&&codeNamev!=null) {
				//向session中放值
				request.getSession().setAttribute("login", user);
				System.out.println(request);System.out.print(user);
				return "success";
			}else {
				return "error";
			}
		}else {
			return "error";
		}
		
	}
	
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getCodeName() {
		return codeName;
	}

	public void setCodeName(String codeName) {
		this.codeName = codeName;
	}

	public String getCodeNamev() {
		return codeNamev;
	}

	public void setCodeNamev(String codeNamev) {
		this.codeNamev = codeNamev;
	}



}
